package com.ly.hotel.spainterface.pp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.ly.hotel.R;

import java.util.List;

/**
 * Created by mo on 2018/6/7.
 */

public class PpXFActionAdapter extends BaseAdapter {

    private Context context;
    private List<String> actions;
    private int defaultPosition = 0;

    public PpXFActionAdapter(Context context, List<String> actions){
        this.context = context;
        this.actions = actions;
    }

    public void setDefaultPosition(int defaultPosition) {
        this.defaultPosition = defaultPosition;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return actions.size();
    }

    @Override
    public Object getItem(int position) {
        return actions.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder = null;
        if(convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.pp_consume_action_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.consumeActionSelect = view.findViewById(R.id.consume_action_select);
            viewHolder.consumeAcitonName = view.findViewById(R.id.consume_aciton_name);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        if(defaultPosition == position){
            viewHolder.consumeActionSelect.setChecked(true);
        }else{
            viewHolder.consumeActionSelect.setChecked(false);
        }
        viewHolder.consumeAcitonName.setText(actions.get(position));
        return view;
    }

    class ViewHolder{
        RadioButton consumeActionSelect;
        TextView consumeAcitonName;
    }
}
